<template>
  <div class="root" :style="{ 'background-image': 'url(' + image + ')' }">
    <div class="login">
      <div class="logo">
        <img src="@/assets/images/logo.png" class="img" />
        <div class="text-1">Victoria Studio</div>
        <div class="text-2">Customer Service System</div>
      </div>
      <el-form class="clear content " ref="ruleFormRef" :model="form">
        <div class="img-qr" v-show="qrLink">
          <img :src="qrLink" class="img" />
        </div>
        <el-form-item v-show="!qrLink" prop="account" class="clear">
          <input class="input" placeholder="Username" v-model="form.name" />
          <div class="sep" />
        </el-form-item>

        <div>
          <el-button class="login_btn" type="primary" @click="sigIn(ruleFormRef)">Add Roler</el-button>
        </div>

      </el-form>
    </div>
  </div>
</template>
<script lang="ts">
import { defineComponent, ref } from 'vue'
import { login } from '@/composables/login'
import type { FormInstance } from 'element-plus'
import { numberInput } from '@/utils/utils'
import VueQrcode from '@chenfengyuan/vue-qrcode'
import http from '@/http'
export default defineComponent({
  components: {
    VueQrcode
  },
  setup() {
    const image = new URL(`./default/images/bg.jpg`, import.meta.url).href
    const {
      rules,
      ruleFormRef,
      submitForm
    } = login()
    const form = ref({
      name: '',
    })
    const qrLink = ref('')
    const sigIn = (formEl: FormInstance | undefined) => {
      console.log(form.value)
      submitForm(formEl, () => {
        const req = {
          name: form.value.name,
        }
        http.fetchPost('check/role/add', req).then((res: any) => {
          qrLink.value = res.data
        })
      })
    }

    return {
      image,
      form,
      rules,
      ruleFormRef,
      sigIn,
      numberInput,
      qrLink
    }
  }
})
</script>
<style lang="scss" scoped>
.root {
  height: 100vh;
  display: flex;
  flex-direction: column;
  justify-content: center;
  /* 背景图垂直、水平均居中 */
  background-position: center center;
  /* 背景图不平铺 */
  background-repeat: no-repeat;
  /* 当内容高度大于图片高度时，背景图像的位置相对于viewport固定 */
  background-attachment: fixed;
  /* 让背景图基于容器大小伸缩 */
  background-size: cover;
}

.content {
  width: 430px;
  margin: 188px auto;
}

.login {
  margin: 0 auto;
  width: 600px !important;
  height: 544px;
  background: rgba(255, 255, 255, .4);
  border-radius: 16px;
  color: white;
  text-align: left;
  position: relative;

  .login_btn {
    margin-top: 64px;
    width: 140px;
    height: 64px;
    line-height: 64px;
    width: 430px;
    border-radius: 16px;
    font-size: 20px;
    background: #0084FF;
  }

  .input {
    border-radius: 16px;
    width: 430px;
    font-size: 16px;
    border: 1px solid white;
    padding-left: 21px;
    height: 64px;
  }

  .sep {
    margin-bottom: 36px;
  }
}

.logo {
  color: black;
  text-align: center;
  margin-bottom: 24px;
  position: absolute;
  left: 0;
  right: 0;
  top: -48px;

  .text-1 {
    font-family: Montserrat;
    font-size: 30px;
    font-weight: 700;
    line-height: 37px;
    letter-spacing: 0em;
    text-align: center;
    margin-bottom: 18px;
  }

  .text-2 {
    font-family: Montserrat;
    font-size: 18px;
    font-weight: 500;
    line-height: 22px;
    letter-spacing: 0em;
    text-align: center;
  }

  .img {
    width: 96px;
    height: 96px;
    border-radius: 16px;
  }
}

.img-qr {
  text-align: center;
  .img{
    width: 130px;

  }
}
</style>
